<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>新闻公告添加</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <include file="Index/common_css"/>
    <link href="__PUBLIC__/admin/css/plugins/iCheck/custom.css" rel="stylesheet">
</head>

<body>
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <form action="" method="post" class="form form-horizontal" id="form-admin-role-add" enctype="multipart/form-data">

            <div class="form-group">
                <label class="col-sm-3 control-label">标题：</label>
                <div class="col-sm-8">
                    <input id="title" name="title"  class="form-control" type="text"  datatype="*4-16" placeholder="标题">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">封面图片：</label>
                <div class="col-sm-8">
                    <input id="img" type="file" name="img"  class="form-control">
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">类型：</label>
                <div class="col-sm-8">
                    <select name="type" id="type" class="input-sm form-control input-s-sm inline">
                        <option value="1">公告</option>
                        <option value="2">资讯</option>
                        <option value="3">新闻</option>
                    </select>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">内容：</label>
                <div class="col-sm-8">

                    <textarea id="editor"  name="content" type="text/plain" style="height:550px;"></textarea>
                </div>
            </div>


            <div class="row cl">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                    <button type="button" class="btn btn-success radius"  onclick="article_add()" id="admin-role-save" name="admin-role-save">
                        <i class="icon-ok"></i> 保存
                    </button>

                    <a style="margin-left: 20px;" href="articleList.html" class="btn btn-success btn-warning">
                        <i class="icon-ok"></i> 返回
                    </a>
                </div>
            </div>
        </form>
    </div>
</div>
<!-- 全局js -->
<include file="Index/common_js"/>
<!-- Peity -->

<!-- 自定义js -->
<script src="__PUBLIC__/admin/js/content.js?v=1.0.0"></script>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/admin/js/ueditor/1.4.3/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/admin/js/ueditor/1.4.3/ueditor.all.min.js"> </script>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/admin/js/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
<!-- iCheck -->
<script src="__PUBLIC__/admin/js/plugins/iCheck/icheck.min.js"></script>
<!-- Peity -->
<script type="text/javascript">
    UE.getEditor('editor');

</script>
<script>
    //我们是共产主义的接班人
    function article_add() {
        var title= $("#title").val();
        var type = $("#type").val();
        var content = UE.getEditor('editor').getContent();
        var filepath =$("#img").val();
        var extStart= filepath.lastIndexOf(".");
        var ext= filepath.substring(extStart,filepath.length).toUpperCase();
        if(ext!=".BMP" && ext!=".PNG" && ext!=".GIF" && ext!=".JPG" && ext!=".JPEG") {
            layer.msg("图片限于png,gif,jpeg,jpg格式");return;
        }
        if(title=='' || type==''|| content=='') {
            layer.msg('所有内容不能为空');return;
        } else {
            var index = layer.load(0, {shade: false});
            var form = document.getElementById('form-admin-role-add');
            fdata = new FormData(form);
            XHR = new XMLHttpRequest();
            XHR.open('POST','__MODULE__/Index/article_addData',true);
            XHR.onreadystatechange=function(){
                if(XHR.readyState == 4) {
                    layer.close(index);layer.msg(XHR.responseText, {time: 1000});
                    //setTimeout(function () {location.reload();}, 1100);
                }
            };
            XHR.send(fdata);
        }
    }
</script>
</body>
</html>
